from random import randrange

from tombola import Tombola


@Tombola.register  # <1>
class TomboList(list):  # <2>
    """
    >>> tl = TomboList()
    >>> issubclass(TomboList, Tombola), issubclass(TomboList, list)
    (True, True)
    >>> isinstance(tl, Tombola), isinstance(tl, list)
    (True, True)
    >>> TomboList.__mro__  # method resolve order 方法解析路径.NOTE Tombola 是虚拟超类
    (<class '__main__.TomboList'>, <class 'list'>, <class 'object'>)
    """

    def pick(self):
        if self:  # <3>
            position = randrange(len(self))
            return self.pop(position)  # <4>
        else:
            raise LookupError("pop from empty TomboList")

    load = list.extend  # <5>

    def loaded(self):
        return bool(self)  # <6>

    def inspect(self):
        return tuple(sorted(self))


# Tombola.register(TomboList)  # <7> python2 语法

if __name__ == "__main__":
    import doctest

    print("tombolist 测试开始")
    (ff, tt) = doctest.testmod()
    print("测试结束:统计-失败{},总计{}".format(ff, tt))
    print("√" * tt if tt > 0 and not ff else "无测试" if not ff else "×" * ff)
